#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#define MAX_LEN 64

int main(int argc, char **argv)
{
	int fd;
	int len;
	char buf_r[MAX_LEN + 1];
	char buf_w[MAX_LEN + 1] = "hello world";

	//open
	fd = open("/dev/hello_dev", O_RDWR);
	if(fd < 0) {
		perror("open error \n");
		return 0;
	}
	printf("open success \n");

	//read
	len = read(fd, buf_r, MAX_LEN);
	buf_r[len] = '\0';
	printf("read: %s, size: %d \n", buf_r, len);

	//write
	len = write(fd, buf_w, strlen(buf_w));
	printf("write: %s, size: %d \n", buf_w, len);

	//close
	close(fd);
	printf("close() \n");

	return 0;
}
